package org.fullhappy.bean;


import java.io.Serializable;
import java.util.ArrayList;
import javax.annotation.PostConstruct;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.model.SelectItem;
import org.fullhappy.business.MusicCategoryService;
import org.fullhappy.model.MenuItemModel;

@ManagedBean
@SessionScoped
public class MenuController implements Serializable {

    private ArrayList<MenuItemModel> menuItems;
    private MusicCategoryService musicCategoryService;
    @PostConstruct
    private void init(){
        menuItems = new ArrayList<MenuItemModel>(1);
        musicCategoryService = new MusicCategoryService();
        loadMenuData();
    }
    
    private void loadMenuData(){
        MenuItemModel menuItem = new MenuItemModel("music","music");
        ArrayList<MenuItemModel> subMenuItems = new ArrayList<MenuItemModel>(1);
        ArrayList<SelectItem> selectItems = musicCategoryService.getSelectItems();
        for(SelectItem item: selectItems){
            subMenuItems.add(new MenuItemModel(item.getLabel(), "music/List.xhtml?category="+item.getValue()));
        }
        menuItem.setSubMenuItems(subMenuItems);
        menuItems.add(menuItem);
    }

    public ArrayList<MenuItemModel> getMenuItems() {
        return menuItems;
    }

    public void setMenuItems(ArrayList<MenuItemModel> menuItems) {
        this.menuItems = menuItems;
    }

    public MusicCategoryService getMusicCategoryService() {
        return musicCategoryService;
    }

    public void setMusicCategoryService(MusicCategoryService musicCategoryService) {
        this.musicCategoryService = musicCategoryService;
    }    
}
